package com.xyht.medicine_management_system.modules.coupon.controller;


import com.xyht.medicine_management_system.auth.util.JwtTokenUtil;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.medicine_management_system.modules.coupon.entity.req.MmsUserCouponRelationReq;
import com.xyht.medicine_management_system.modules.coupon.service.MmsUserCouponRelationService;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 优惠劵表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-12-03
 */
@RestController
@SecretBody
@RequestMapping("/userCoupon")
public class MmsUserCouponRelationController {
    @Resource
    private MmsUserCouponRelationService mmsUserCouponRelationService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty("用户领取优惠券")
    @PostMapping("/get")
    public ResponseResult getCoupon(@RequestBody MmsUserCouponRelationReq userCouponRelation, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return mmsUserCouponRelationService.getCoupon(userCouponRelation, userId);
    }

    @ApiOperation("获取本人优惠券列表")
    @GetMapping("/list")
    public ResponseResult getCouponList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                        @RequestParam(value = "status", required = false) Integer status, // 0.可使用 1.已使用 2.已失效
                                        @RequestParam(value = "searchStr", required = false) String searchStr,
                                        HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return mmsUserCouponRelationService.getCouponList(pageNum, pageSize, status, searchStr, userId);
    }
}

